﻿@{
    ViewBag.Title = "全部文件";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using Wolfy.NetDisk.Site.Utils;
@model   Wolfy.NetDisk.Site.Models.HomeViewModel
<form method="post" enctype="multipart/form-data" id="mainform">

    <button class="btn btn-primary btn-margin-left-10" id="btnNewFolder">新建文件夹</button>
    <button class="btn btn-primary btn-margin-left-10" id="btnUploadFile">上传文件</button>
    <input type="file" style="display:none;" name="name" value="" id="fileUpload" />
    <p>
        <span><a href="javascript:void(0)" class="file-box" path="/" id="lnkPath">全部文件</a></span>
    </p>
    @if (Model.Files.Count() > 0)
    {
        <table class="table sortable-list">
            <tr>
                <th class="">文件名</th>
                <th>大小</th>
                <th>修改日期</th>
                <th>操作</th>
            </tr>

            @foreach (var item in Model.Files)
            {
                <tr id="tr-@item.Id">
                    <td><img src="@item.Icon.Path" /> @item.Name</td>
                    <td>@Extentions.ToMB(item.Size * 1.0)</td>
                    <td>@item.Dt</td>
                    <td>

                        <a href="javascript:void(0)" onclick="deleteFile(@item.Id)">删除</a>

                        @Html.ActionLink("编辑", "EditFile", new { id = @item.Id }, new { style = "margin-left:10px;" })
                        @Html.ActionLink("下载", "DownLoadFile", new { id = @item.Id }, new { style = "margin-left:10px;" })
                    </td>
                </tr>

            }
        </table> }
    else
    {
        <p style="float:left;">没有内容哦~</p>
    }
</form>
<script>
    $("#fileUpload").change(function () {
        $("#mainform").ajaxSubmit({
            url: "@Url.Content("~/netdisk/PostedFile")",
            type: "post",
            target: "#file-table-tr-header",//刷新的区域
            data: { path: $("#lnkPath").attr("path") },
            dataType: "json",
            clearForm: true,       // clear all form fields after successful submit
            resetForm: true,       // reset the form after successful submit
            success: function (data) {
                console.log(data);
                data = JSON.parse(data);
                console.log(data);
                if (data._code == 200) {
                    $(" <tr><td><img src=\"" + data._data.file.Icon + "\" />" + data._data.file.Name + "</td><td>" + data._data.file.Size + "</td><td>" + data._data.file.Dt + "</td></tr>").appendTo($(".table"));
                };
            },
            error: function (aa) {
                console.log(aa);
            }
        });
        return false;
    });
    $("#btnUploadFile").on("click", function () {
        $("#fileUpload").click();
        return false;
    });
    $("#btnNewFolder").on("click", function () {

        return false;
    });
    //删除文件
    function deleteFile(id) {
        var $tr = $("#tr-" + id);
        //删除本行
        $tr.remove();
        $.getJSON("@Url.Content("~/netdisk/DeleteFile")"+"?id=" + id, function (data) {

        });
    };
</script>
